package org.su.webadapter.render;

import org.su.generalmvc.IModel;
import org.su.generalmvc.render.IRender;
import org.apache.commons.io.IOUtils;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class StreamRender implements IRender {
	@Override
	public void render(IModel model, Object result, String defaultPath, ServletRequest request,
			ServletResponse response) throws IOException {
		if (null != model) {
			InputStream in = (InputStream) model.getInputStream();
			if (in != null) {
				OutputStream out = response.getOutputStream();
				try {
					IOUtils.copy(in, out);
				} finally {
					try {
						in.close();
					} finally {
						out.close();
					}
				}
			}
		}

	}

}
